package com.logistics.route.controller;

import com.logistics.route.entity.model.RoutePager;
import com.logistics.route.entity.model.RouteSave;
import com.logistics.route.service.RouteService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("sys/route")
public class RouteController {

    @Autowired
    private RouteService routeService;

    /**
     * 分页查询
     * @param param
     * @return
     */
    @PostMapping("pager")
    @LoggerListener(businessName = "分页查询路由列表", methodName = LoggerMethod.SEARCH)
    public ResponseEntity pager(@RequestBody RoutePager param){
        return ResponseUtil.success(routeService.pager(param));
    }

    /**
     * 查找全部
     * @return
     */
    @GetMapping("listAll")
    @LoggerListener(businessName = "查找全部路由信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity listAll(){
        return ResponseUtil.success(routeService.listAll());
    }

    /**
     * 根据ID查找路由
     * @param ids
     * @return
     */
    @GetMapping("listByIds/{ids}")
    @LoggerListener(businessName = "根据ID查询路由信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity listByIds(@PathVariable(value = "ids") String ids) throws MessageException {
        return ResponseUtil.success(routeService.listByIds(ids));
    }
    /**
     * 查询详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("details/{id}")
    @LoggerListener(businessName = "查询路由详细信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity details(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(routeService.details(id));
    }

    /**
     * 保存
     * @param save
     * @return
     */
    @PutMapping("save")
    @LoggerListener(businessName = "保存路由信息", methodName = LoggerMethod.SAVE)
    public ResponseEntity save(@RequestBody RouteSave save){
        routeService.save(save);
        return ResponseUtil.success();
    }

    /**
     * 删除
     * @param ids
     * @return
     * @throws MessageException
     */
    @DeleteMapping("remove/{ids}")
    @LoggerListener(businessName = "删除路由信息", methodName = LoggerMethod.DELETE)
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        routeService.remove(ids);
        return ResponseUtil.success();
    }
}
